<template>
  <div class="pagebox app-container aCnopadding">
    <a-row :gutter="16">
      <a-col class="gutter-row" :span="5">
        <!--      新创建设备-->
        <div class="gutter-box">
          <new-equipment :NewestFiveArchive="NewestFiveArchive"></new-equipment>
        </div>
        <!--      设备类型-->
        <div>
          <equipment-type :MacTypeCountData="MacTypeCountData"></equipment-type>
        </div>
        <!--      当日报警-->
        <div>
          <today-alarm :AlarmList="AlarmList" />
        </div>
      </a-col>
      <a-col class="gutter-row" :span="14">
        <!--      中间数量-->
        <div class="gutter-box">
          <div>
            <equipment-num
              :msgFormSon="msgFormSon"
              :OnlineRateAndNetRate="OnlineRateAndNetRate"
              :Onlineequ="ArchiveOnline"
              :haveEQUcount="geoData.length"
            />
          </div>
          <div style="width: 100%; height: 1000px">
            <china-map :geoData="geoData" v-if="geoData.length > 0" style="margin-top: 20px"></china-map>
          </div>
        </div>
        <!--        <div>-->
        <!--          -->
        <!--        </div>-->
      </a-col>
      <a-col class="gutter-row" :span="5">
        <!--      右侧设备统计-->
        <div class="gutter-box">
          <equipment-statistics
            @expected="getMsgFormSon"
            :ArchiveCount="ArchiveCount"
            :ArchiveOnline="ArchiveOnline"
            :ActiveUser="ActiveUser"
            :startTime="Parames.startTime"
            :endTime="Parames.endTime"
          />
        </div>
      </a-col>
    </a-row>
  </div>
</template>

<script>
import newEquipment from './component/newEquipment';
import equipmentType from './component/equipmentType';
import todayAlarm from './component/todayAlarm';
import equipmentNum from './component/equipmentNum';
import chinaMap from './component/chinaMap';
import equipmentStatistics from './component/equipmentStatistics';
import api from '@/api/map.js';
import wapi from '@/api/workshop';
import { timeCalculation } from '../../unit/tool';

export default {
  name: 'index',
  components: {
    newEquipment,
    equipmentType,
    todayAlarm,
    equipmentNum,
    equipmentStatistics,
    chinaMap,
  },
  data() {
    return {
      compId: null,
      ArchiveCount: [],
      ActiveUser: [],
      ArchiveOnline: [],
      NewestFiveArchive: null,
      OnlineRateAndNetRate: null,
      AlarmList: null,
      geoData: [],
      Parames: {},
      MacTypeCountData: [],
      msgFormSon:""
    };
  },
  created() {
    this.$store.commit('board/HeadNavType', 3);
    // this.Parames.UserName = localStorage.getItem("userName");
    this.Parames.compId = this.compId = localStorage.getItem('compid');
    let startTime = timeCalculation(new Date(), 'subtract', 7);
    let endTime = timeCalculation(new Date(), 'subtract', 1);
    this.Parames.startTime = String(startTime);
    this.Parames.endTime = String(endTime);
    this.getNewestFiveArchive();
    this.getArchiveCountByDay();
    this.getArchiveOnlineByDay();
    this.selActiveUserByDay();
    this.getOnlineRateAndNetRate();
    this.MacAlarmStatisticByCompId();
    this.SelArchivesByCompid();
    this.getMacTypeCount();
  },
  methods: {
    getMsgFormSon(data) {
      this.msgFormSon = data;
      console.log(this.msgFormSon,'传值');
    },

    //报警分析
    MacAlarmStatisticByCompId() {
      let params = {
        compId: this.Parames.compId,
        startTime: timeCalculation(new Date(), 'subtract', 0) + ' 00:00:00',
        endTime: timeCalculation(new Date(), 'subtract', 0) + ' 23:59:59',
      };
      wapi.MacAlarmStatisticByCompId(params).then((res) => {
        this.AlarmList = res.Data;
      });
    },
    //最新设备
    getNewestFiveArchive() {
      api.getNewestFiveArchive({ compId: this.compId }).then((res) => {
        this.NewestFiveArchive = res.Data;
      });
    },
    //上线率和在线率
    getOnlineRateAndNetRate() {
      api.getOnlineRateAndNetRate({ compId: this.compId }).then((res) => {
        this.OnlineRateAndNetRate = res.Data;
      });
    },
    //累计设备
    getArchiveCountByDay() {
      api.getArchiveCountByDay(this.Parames).then((res) => {
        this.ArchiveCount = res.Data;
      });
    },
    //上线设备
    getArchiveOnlineByDay() {
      api.getArchiveOnlineByDay(this.Parames).then((res) => {
        this.ArchiveOnline = res.Data;
      });
    },
    //活跃用户
    selActiveUserByDay() {
      this.Parames.endTime = timeCalculation(new Date(), 'subtract', 0);
      api.selActiveUserByDay(this.Parames).then((res) => {
        if (res.Data) {
          this.ActiveUser = res.Data;
        } else {
          this.ActiveUser = [];
        }
      });
    },
    //查询厂已接入设备信息
    SelArchivesByCompid() {
      api.SelArchivesByCompid({ compid: this.Parames.compId }).then((res) => {
        this.geoData = res.Data;
        console.log(res.Data, '输出');
      });
    },
    //设备类型
    getMacTypeCount() {
      api.getMacTypeCount({ compId: this.Parames.compId }).then((res) => {
        this.MacTypeCountData = res.Data;
      });
    },

    changedate(i) {
      this.dateType = i;
    },
  },
};
</script>

<style scoped>
@import 'light.less';
</style>
